import wx from 'weixin-js-sdk'
import { getWeixinSignApi } from '@/apis/user'

// 微信分享
export const wxShare = ({ title, desc, link, imgUrl }) => {
  getWeixinSignApi([
    'onMenuShareTimeline',
    'onMenuShareAppMessage',
    'onMenuShareQQ',
    'onMenuShareWeibo',
    'onMenuShareQZone'
  ])
  wx.ready(() => {
    var shareData = {
      title,
      desc,
      link,
      imgUrl,
      success: () => {},
      cancel: () => {}
    }
    wx.onMenuShareTimeline(shareData)
    wx.onMenuShareAppMessage(shareData)
    wx.onMenuShareQQ(shareData)
    wx.onMenuShareWeibo(shareData)
    wx.onMenuShareQZone(shareData)
  })
}

//禁止分享
export const wxNoShare = () => {
  getWeixinSignApi(['hideOptionMenu', 'hideMenuItems', 'hideAllNonBaseMenuItem'])
  wx.ready(() => {
    wx.hideAllNonBaseMenuItem()
  })
}
